<?php
!defined('IN_ROOT') && exit('Access Denied');

class doccontrol extends base {

    function doccontrol(& $get,& $post) {
        $this->base( & $get,& $post);
        $this->load("doc");
        //$this->load('area');
        //$this->load('cate');
        //$this->load('sysmap');
    }
    
    function onmanage()
    {
    	$uid = $this->user['uid'];
    	$where = " `uid`='$uid'";
    	$page = $this->get[2] ? $this->get[2] : 1;
    	$perpage = 20;
    	
    	$list = $_ENV['doc']->get_list($page-1, $perpage, $where);
    	include template('docmanage');
    }
    
    function onpublic()
    {
    	$uid = $this->user['uid'];
    	if (isset($this->post['submit'])) {
    		require 'lib/upload.class.php';
    		$data = $this->post['data'];
    		$data['uid'] = $uid;
    		//require 'lib/upload.class.php';
    		if ($_FILES['fileurl']['name'][0]) {
    			$data['filename'] = $_FILES['fileurl']['name'][0];
    			$savePath = 'upload/'.date('Y-m-d', time()).'/';
    			$upload = new upload('fileurl',$savePath, 'doc|docx|wps', 1000000);
    			$image = $upload->up();
    			if ($image[0]) {
    				$data['fileurl'] = $image[0]['saveto'];
    			}
    		} else {
    			msg('请选择图片！');
    		}
    		$data['download'] = 0;
    		$data['created'] = time();
    		$_ENV['doc']->add($data);
    		msg('发布成功！', '?doc/manage');
    	} else {
    		include template('docpublic');
    	}
    }
    
    function onedit()
    {
    	$doc_id = $this->get[2];
    	!$doc_id && msg('非法操作！', '/?doc/manage');
		$uid = $this->user['uid'];
    	if (isset($this->post['submit'])) {
    		require 'lib/upload.class.php';
    		$data = $this->post['data'];
    		if ($_FILES['fileurl']['name'][0]) {
    			$data['filename'] = $_FILES['fileurl']['name'][0];
    			$savePath = 'upload/'.date('Y-m-d', time()).'/';
    			$upload = new upload('fileurl',$savePath, 'doc|docx|wps', 1000000);
    			$image = $upload->up();
    			if ($image[0]) {
    				$data['fileurl'] = $image[0]['saveto'];
    			}
    		} else {
    			//msg('请选择图片！');
    		}
    		$_ENV['doc']->update($data, $doc_id);
    		msg('修改成功！', '?doc/manage');
    	} else {
    		$docinfo = $_ENV['doc']->get($doc_id);
    		include template('docpublic');
    	}
    }
    
    function ondelete()
    {
    	$doc_id = $this->get[2];
    	!$doc_id && msg('非法操作！', '/?doc/manage');
		$uid = $this->user['uid'];
		$_ENV['doc']->delete($doc_id);
		msg('删除成功！', '?doc/manage');
    }
}
?>